home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_15 / sblaster.qrf
Text File  |  1995-01-01  |  19KB  |  425 lines

  1. From voyager!apctrc!uc.msc.edu!mips!zaphod.mps.ohio-state.edu!
  2.      qt.cs.utexas.edu!news!noc.near.net!uhasun!smylex!jlee
  3.       Mon Nov 18 12:53:14 CST 1991
  4. Article: 4702 of comp.music
  5. Xref: voyager rec.games.programmer:4283 comp.music:4702
  6. Path: voyager!apctrc!uc.msc.edu!mips!zaphod.mps.ohio-state.edu!
  7.       qt.cs.utexas.edu!news!noc.near.net!uhasun!smylex!jlee
  8. From: jlee@smylex.UUCP (Jeff Lee)
  9. Newsgroups: rec.games.programmer,comp.music
  10. Subject: At long last -- the AdLib / SoundBlaster Quick-Reference!
  11. Message-ID: <143-JNEWS-1.2@smylex.UUCP>
  12. Date: 15 Nov 91 19:50:50 GMT
  13. Sender: jlee@smylex.UUCP
  14. Organization: The SMYLEX Usenet BBS  (Newington, CT)
  15. Lines: 406
  16.  
  17. Many apologies for the delay -- but here it is, finally...
  18.  
  19. ---------------------------------- cut here ----------------------------------
  20.  
  21.  
  22.                       Programming the AdLib/Sound Blaster
  23.                                 FM Music Chips
  24.                              Quick Reference Guide
  25.  
  26.                      Copyright (c) 1991 by Jeffrey S. Lee
  27.  
  28.                                jlee@smylex.uucp
  29.  
  30.  
  31.  
  32.                         Warranty and Copyright Policy
  33.  
  34.      This document is provided on an "as-is" basis, and its author makes
  35.      no warranty or representation, express or implied, with respect to
  36.      its quality performance or fitness for a particular purpose.  In no
  37.      event will the author of this document be liable for direct, indirect,
  38.      special, incidental, or consequential damages arising out of the use
  39.      or inability to use the information contained within.  Use of this
  40.      document is at your own risk.
  41.  
  42.      This file may be used and copied freely so long as the applicable
  43.      copyright notices are retained, and no modifications are made to the
  44.      text of the document.  No money shall be charged for its distribution
  45.      beyond reasonable shipping, handling and duplication costs, nor shall
  46.      proprietary changes be made to this document so that it cannot be
  47.      distributed freely.  This document may not be included in published
  48.      material or commercial packages without the written consent of its
  49.      author.
  50.  
  51.  
  52.  
  53.                                    Overview
  54.  
  55.      Two of the most popular sound cards for the IBM-PC, the AdLib and the
  56.      Sound Blaster, suffer from a real dearth of clear documentation for 
  57.      programmers.  AdLib Inc. and Creative Labs, Inc. both sell developers'
  58.      kits for their sound cards, but these are expensive, and (in the case
  59.      of the Sound Blaster developers' kit) can be extremely cryptic.
  60.  
  61.      This document is intended to provide programmers with a FREE source
  62.      of information about the programming of these sound cards.
  63.  
  64.      The information contained in this document is a combination of 
  65.      information found in the Sound Blaster Software Developer's Kit, and
  66.      that learned by painful experience.  Some of the information may not
  67.      be valid for AdLib cards; if this is so, I apologize in advance.
  68.  
  69.      Please note that numbers will be given in hexadecimal, unless otherwise
  70.      indicated.  If a number is written out longhand (sixteen instead of 16)
  71.      it is in decimal.  Bits within a byte are numbered from 0 (the rightmost,
  72.      least significant bit) to 7 (the leftmost, most significant bit).  Sound
  73.      channels are likewise numbered; the nine channels will be designated as
  74.      channels 0 through 8.
  75.  
  76.  
  77.  
  78.  
  79.                          Chapter One - Sound Card I/O
  80.  
  81.      The sound card is programmed by sending data to its internal registers
  82.      via its two I/O ports:
  83.  
  84.              0388 (hex) - Address/Status port  (R/W)
  85.              0389 (hex) - Data port            (W/O)
  86.  
  87.      The sound card possesses an array of two hundred forty-four registers;
  88.      to write to a particular register, send the register number (01-F5) to
  89.      the address port, and the desired value to the data port.
  90.  
  91.      After writing to the register port, you must wait twelve cycles before 
  92.      sending the data; after writing the data, eighty-four cycles must elapse
  93.      before any other sound card operation may be performed.
  94.  
  95.      The sound card registers are write-only.
  96.  
  97.      The address port also functions as a sound card status byte.  To 
  98.      retrieve the sound card's status, simply read port 0388.  The status 
  99.      byte has the following structure:
  100.  
  101.               7      6      5      4      3      2      1      0
  102.           +------+------+------+------+------+------+------+------+
  103.           | both | tmr  | tmr  |              unused              |
  104.           | tmrs |  1   |  2   |                                  |
  105.           +------+------+------+------+------+------+------+------+
  106.  
  107.           Bit 7 - set if either timer has expired.
  108.               6 - set if timer 1 has expired.
  109.               5 - set if timer 2 has expired.
  110.  
  111.  
  112.  
  113.                        Chapter Two - The Registers
  114.  
  115. The following table shows the function of each register in the sound 
  116. card.  Registers will be explained in detail after the table.  Registers
  117. not listed are unused.
  118.  
  119.    Address      Function
  120.    -------      ----------------------------------------------------
  121.      01         Test LSI / Enable waveform control
  122.      02         Timer 1 data
  123.      03         Timer 2 data
  124.      04         Timer control flags
  125.      08         Speech synthesis mode / Keyboard split note select
  126.    20..35       Amp Mod / Vibrato / EG type / Key Scaling / Multiple
  127.    40..55       Key scaling level / Operator output level
  128.    60..75       Attack Rate / Decay Rate
  129.    80..95       Sustain Level / Release Rate
  130.    A0..A8       Frequency (low 8 bits)
  131.    B0..B8       Key On / Octave / Frequency (high 2 bits)
  132.      BD         AM depth / Vibrato depth / Rhythm control
  133.    C0..C8       Feedback strength / Connection type
  134.    E0..F5       Wave Select
  135.  
  136. The groupings of twenty-two registers (20-35, 40-55, etc.) have an odd
  137. order due to the use of two operators for each FM voice.  The following
  138. table shows the offsets within each group of registers for each operator.
  139.  
  140.  
  141.    Channel        1   2   3   4   5   6   7   8   9
  142.    Operator 1    00  01  02  08  09  0A  10  11  12
  143.    Operator 2    03  04  05  0B  0C  0D  13  14  15
  144.  
  145. Thus, the addresses of the attack/decay bytes for channel 3 are 62 for
  146. the first operator, and 65 for the second.  (The address of the second
  147. operator is always the address of the first operator plus three).
  148.  
  149. To further illustrate the relationship, the addresses needed to control
  150. channel 5 are:
  151.  
  152.     29 - Operator 1  AM/VIB/EG/KSR/Multiplier
  153.     2C - Operator 2  AM/VIB/EG/KSR/Multiplier
  154.     49 - Operator 1  KSL/Output Level
  155.     4C - Operator 2  KSL/Output Level
  156.     69 - Operator 1  Attack/Decay
  157.     6C - Operator 2  Attack/Decay
  158.     89 - Operator 1  Sustain/Release
  159.     8C - Operator 2  Sustain/Release
  160.     A4 -             Frequency (low 8 bits)
  161.     B4 -             Key On/Octave/Frequency (high 2 bits)
  162.     C4 -             Feedback/Connection Type
  163.     E9 - Operator 1  Waveform
  164.     EC - Operator 2  Waveform
  165.  
  166.  
  167.  
  168.                        Explanations of Registers
  169.  
  170. Byte 01 - This byte is normally used to test the LSI device.  All bits
  171.           should normally be zero.  Bit 5, if enabled, allows the FM 
  172.           chips to control the waveform of each operator.
  173.  
  174.              7     6     5     4     3     2     1     0
  175.           +-----+-----+-----+-----+-----+-----+-----+-----+
  176.           |   unused  | WS  |            unused           |
  177.           +-----+-----+-----+-----+-----+-----+-----+-----+
  178.  
  179.  
  180. Byte 02 - Timer 1 Data.  If Timer 1 is enabled, the value in this 
  181.           register will be incremented until it overflows.  Upon
  182.           overflow, the sound card will signal a TIMER interrupt
  183.           (INT 08) and set bits 7 and 6 in its status byte.  The
  184.           value for this timer is incremented every eighty (80)
  185.           microseconds.
  186.  
  187.  
  188. Byte 03 - Timer 2 Data.  If Timer 2 is enabled, the value in this 
  189.           register will be incremented until it overflows.  Upon
  190.           overflow, the sound card will signal a TIMER interrupt
  191.           (INT 08) and set bits 7 and 5 in its status byte.  The
  192.           value for this timer is incremented every three hundred
  193.           twenty (320) microseconds.
  194.  
  195.  
  196. Byte 04 - Timer Control Byte
  197.  
  198.         7     6     5     4     3     2     1     0
  199.      +-----+-----+-----+-----+-----+-----+-----+-----+
  200.      | IRQ | T1  | T2  |     unused      | T2  | T1  |
  201.      | RST | MSK | MSK |                 | CTL | CTL |
  202.      +-----+-----+-----+-----+-----+-----+-----+-----+
  203.  
  204.           bit 7 - Resets the flags for timers 1 & 2.  If set,
  205.                   all other bits are ignored.
  206.           bit 6 - Masks Timer 1.  If set, bit 0 is ignored.
  207.           bit 5 - Masks Timer 2.  If set, bit 1 is ignored.
  208.           bit 1 - When clear, Timer 2 does not operate.
  209.                   When set, the value from byte 03 is loaded into
  210.                   Timer 2, and incrementation begins.
  211.           bit 0 - When clear, Timer 1 does not operate.
  212.                   When set, the value from byte 02 is loaded into
  213.                   Timer 1, and incrementation begins.
  214.  
  215.  
  216. Byte 08 - CSM Mode / Keyboard Split.
  217.  
  218.         7     6     5     4     3     2     1     0
  219.      +-----+-----+-----+-----+-----+-----+-----+-----+
  220.      | CSM | Key |              unused               |
  221.      | sel | Spl |                                   |
  222.      +-----+-----+-----+-----+-----+-----+-----+-----+
  223.      
  224.           bit 7 - When set, selects composite sine-wave speech synthesis
  225.                   mode (all KEY-ON bits must be clear).  When clear,
  226.                   selects FM music mode.
  227.  
  228.           bit 6 - Selects the keyboard split point (in conjunction with
  229.                   the F-Number data).  The documentation in the Sound 
  230.                   Blaster manual is utterly incomprehensible on this;
  231.                   I can't reproduce it without violating their copyright.
  232.  
  233.  
  234. Bytes 20-35 - Amplitude Modulation / Vibrato / Envelope Generator Type /
  235.               Keyboard Scaling Rate / Modulator Frequency Multiple
  236.  
  237.         7     6     5     4     3     2     1     0
  238.      +-----+-----+-----+-----+-----+-----+-----+-----+
  239.      | Amp | Vib | EG  | KSR |  Modulator Frequency  |
  240.      | Mod |     | Typ |     |       Multiple        |
  241.      +-----+-----+-----+-----+-----+-----+-----+-----+
  242.  
  243.           bit 7 - Apply amplitude modulation when set; AM depth is
  244.                   controlled by the AM-Depth flag in address BD.
  245.           bit 6 - Apply vibrato when set;  vibrato depth is controlled
  246.                   by the Vib-Depth flag in address BD.
  247.           bit 5 - When set, the sustain level of the voice is maintained
  248.                   until released; when clear, the sound begins to decay
  249.                   immediately after hitting the SUSTAIN phase.
  250.           bit 4 - Keyboard scaling rate.  This is another incomprehensible
  251.                   bit in the Sound Blaster manual.  From experience, if 
  252.                   this bit is set, the sound's envelope is foreshortened as
  253.                   it rises in pitch.
  254.           bits 3-0 - These bits indicate which harmonic the operator will 
  255.                   produce sound (or modulation) in relation to the voice's 
  256.                   specified frequency:
  257.  
  258.                       0 - one octave below
  259.                       1 - at the voice's specified frequency
  260.                       2 - one octave above
  261.                       3 - an octave and a fifth above
  262.                       4 - two octaves above
  263.                       5 - two octaves and a major third above
  264.                       6 - two octaves and a fifth above
  265.                       7 - two octaves and a minor seventh above
  266.                       8 - three octaves above
  267.                       9 - three octaves and a major second above
  268.                       A - three octaves and a major third above
  269.                       B -  "       "     "  "   "     "     "
  270.                       C - three octaves and a fifth above
  271.                       D -   "      "     "  "   "     "
  272.                       E - three octaves and a major seventh above
  273.                       F -   "      "     "  "   "      "      "
  274.                   
  275.  
  276. Bytes 40-55 - Level Key Scaling / Total Level
  277.  
  278.         7     6     5     4     3     2     1     0
  279.      +-----+-----+-----+-----+-----+-----+-----+-----+
  280.      |  Scaling  |             Total Level           |
  281.      |   Level   | 24    12     6     3    1.5   .75 | <-- dB
  282.      +-----+-----+-----+-----+-----+-----+-----+-----+
  283.  
  284.           bits 7-6 - causes output levels to decrease as the frequency
  285.                      rises:
  286.  
  287.                           00   -  no change
  288.                           10   -  1.5 dB/8ve
  289.                           01   -  3 dB/8ve
  290.                           11   -  6 dB/8ve
  291.  
  292.           bits 5-0 - controls the total output level of the operator.
  293.                      all bits CLEAR is loudest; all bits SET is the
  294.                      softest.  Don't ask me why.
  295.  
  296.  
  297. Bytes 60-75 - Attack Rate / Decay Rate
  298.  
  299.         7     6     5     4     3     2     1     0
  300.      +-----+-----+-----+-----+-----+-----+-----+-----+
  301.      |         Attack        |          Decay        |
  302.      |          Rate         |          Rate         |
  303.      +-----+-----+-----+-----+-----+-----+-----+-----+
  304.  
  305.           bits 7-4 - Attack rate.  0 is the slowest, F is the fastest.
  306.           bits 3-0 - Decay rate.  0 is the slowest, F is the fastest.
  307.  
  308.  
  309. Bytes 80-95 - Sustain Level / Release Rate
  310.  
  311.         7     6     5     4     3     2     1     0
  312.      +-----+-----+-----+-----+-----+-----+-----+-----+
  313.      |     Sustain Level     |         Release       |
  314.      | 24    12     6     3  |          Rate         |
  315.      +-----+-----+-----+-----+-----+-----+-----+-----+
  316.  
  317.           bits 7-4 - Sustain Level.  0 is the loudest, F is the softest.
  318.           bits 3-0 - Release Rate.  0 is the slowest, F is the fastest.
  319.  
  320.  
  321. Bytes A0-B8 - Octave / F-Number / Key-On
  322.  
  323.         7     6     5     4     3     2     1     0
  324.      +-----+-----+-----+-----+-----+-----+-----+-----+
  325.      |        F-Number (least significant byte)      |  (A0-A8)
  326.      |                                               |
  327.      +-----+-----+-----+-----+-----+-----+-----+-----+
  328.  
  329.         7     6     5     4     3     2     1     0
  330.      +-----+-----+-----+-----+-----+-----+-----+-----+
  331.      |  Unused   | Key |    Octave       | F-Number  |  (B0-B8)
  332.      |           | On  |                 | most sig. |
  333.      +-----+-----+-----+-----+-----+-----+-----+-----+
  334.  
  335.           bit   5  - Channel is voiced when set, silent when clear.
  336.           bits 4-2 - Octave (0-7).  0 is lowest, 7 is highest.
  337.           bits 1-0 - Most significant bits of F-number.
  338.  
  339.      In octave 4, the F-number values for the chromatic scale and their 
  340.      corresponding frequencies would be:
  341.  
  342.         F Number     Frequency     Note
  343.            16B          277.2       C#
  344.            181          293.7       D
  345.            198          311.1       D#
  346.            1B0          329.6       E
  347.            1CA          349.2       F
  348.            1E5          370.0       F#
  349.            202          392.0       G
  350.            220          415.3       G#
  351.            241          440.0       A
  352.            263          466.2       A#
  353.            287          493.9       B
  354.            2AE          523.3       C
  355.  
  356.  
  357. Bytes C0-C8 - Feedback / Algorithm
  358.  
  359.         7     6     5     4     3     2     1     0
  360.      +-----+-----+-----+-----+-----+-----+-----+-----+
  361.      |         unused        |    Feedback     | Alg |
  362.      |                       |                 |     |
  363.      +-----+-----+-----+-----+-----+-----+-----+-----+
  364.  
  365.           bits 3-1 - Feedback strength.  If all three bits are set to
  366.                      zero, no feedback is present.  With values 1-7,
  367.                      operator 1 will send a portion of its output back
  368.                      into itself.  1 is the least amount of feedback,
  369.                      7 is the most.
  370.           bit 0    - If set to 0, operator 1 modulates operator 2.  In this
  371.                      case, operator 2 is the only one producing sound.
  372.                      If set to 1, both operators produce sound directly.
  373.                      Complex sounds are more easily created if the algorithm
  374.                      is set to 0.
  375.  
  376.  
  377. Byte BD - Amplitude Modulation Depth / Vibrato Depth / Rhythm
  378.  
  379.         7     6     5     4     3     2     1     0
  380.      +-----+-----+-----+-----+-----+-----+-----+-----+
  381.      | AM  | Vib | Rhy | BD  | SD  | TOM | Top | HH  |
  382.      | Dep | Dep | Ena |     |     |     | Cym |     |
  383.      +-----+-----+-----+-----+-----+-----+-----+-----+
  384.  
  385.           bit 7 - Set:    AM depth is 4.8dB
  386.                   Clear:  AM depth is 1 dB
  387.           bit 6 - Set:    Vibrato depth is 14 cent
  388.                   Clear:  Vibrato depth is 7 cent
  389.           bit 5 - Set:    Rhythm enabled  (6 melodic voices) 
  390.                   Clear:  Rhythm disabled (9 melodic voices)
  391.           bit 4 - Bass drum on/off
  392.           bit 3 - Snare drum on/off
  393.           bit 2 - Tom tom on/off
  394.           bit 1 - Cymbal on/off
  395.           bit 0 - Hi Hat on/off
  396.  
  397.           Note:  KEY-ON registers for channels 06, 07, and 08 must be OFF
  398.                  in order to use the rhythm section.  Other parameters
  399.                  such as attack/decay/sustain/release must also be set
  400.                  appropriately.
  401.  
  402.  
  403. Bytes E0-F5 - Waveform Select
  404.  
  405.         7     6     5     4     3     2     1     0
  406.      +-----+-----+-----+-----+-----+-----+-----+-----+
  407.      |               unused              |  Waveform |
  408.      |                                   |  Select   |
  409.      +-----+-----+-----+-----+-----+-----+-----+-----+
  410.  
  411.           bits 1-0 - When bit 5 of address 01 is set, the output waveform
  412.                      will be distorted according to the waveform indicated
  413.                      by these two bits.  I'll try to diagram them here,
  414.                      but this medium is fairly restrictive.
  415.  
  416.          ___              ___            ___    ___       _      _
  417.         /   \            /   \          /   \  /   \     / |    / |
  418.        /_____\_______   /_____\_____   /_____\/_____\   /__|___/__|___
  419.               \     /
  420.                \___/
  421.  
  422.             00              01               10               11
  423.  
  424.  
  425.